# coding: utf-8
from PySide6.QtCore import Qt
from PySide6.QtWidgets import QSizePolicy
from qfluentwidgets import FluentLabelBase, getFont


class CustomBodyLabel(FluentLabelBase):
    def _init(self):
        super()._init()
        self._text = ""
        self.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Fixed)

    def getFont(self):
        return getFont(14)

    def setText(self, text: str):
        self._text = text
        new_text = self.fontMetrics().elidedText(text, Qt.TextElideMode.ElideRight, self.width())
        super().setText(new_text)

    def text(self) -> str:
        return self._text

    def resizeEvent(self, event):
        self.setText(self._text)
        super().resizeEvent(event)
